let Koa=require("koa");
let router=require("koa-router")();
let static=require("koa-static");
let views=require("koa-views");
let nunjucks=require("nunjucks");
let parser=require("koa-parser");
let session=require("koa-session");
let app=new Koa();
app.use(session({
    maxAge:1000*10
},app))
app.keys=["123321"]
app.use(static(__dirname+"/public/手机端"));
app.use(views(__dirname+"/public/手机端",{
    map:{html:"nunjucks"}
}))
app.use(parser())
app.listen(3000);
router.get("/",async ctx=>{
    await ctx.render("手机端首页晓舟")
})
router.get("/video",async ctx=>{
    await ctx.render("video")
})
router.get("/doc",async ctx=>{
    if(ctx.session.names){
        await ctx.render("内容",{
            show:"none",
            hide:"block"
        })
        console.log(111)
    }else{
        await ctx.render("内容",{
            kai:"开通vip",
            cheng:"成为vip",
            show:"block",
            hide:"none"
        })
    }
    
})
router.get("/for",async ctx=>{
    await ctx.render("form")
})
router.post("/form",async ctx=>{
    let name=ctx.request.body.name;
    let pass=ctx.request.body.pass;
    if(name=="admin"&&pass=="123147"){
        ctx.session.names="yi"
        ctx.redirect("video");
    }else{
        await ctx.render("form",{
            qing:"用户名或密码错误"
        })
    }
})
app.use(router.routes())
